import {
  mapGetters
} from 'vuex'

export default {
  // onLoad() {
  //   this.setBadge()
  // },
  onShow() {
    this.virify()
  },
  methods: {
    setBadge() {
      uni.setTabBarBadge({
        index: 2,
        text: this.total.toString()
      })
    },
    virify() {
      if (this.total === 0) {
        uni.removeTabBarBadge({
          index: 2
        })
        return
      }
      this.setBadge()
    }
  },
  computed: {
    ...mapGetters('cart', ['total'])
  },
  watch: {
    total: {
      immediate: true,
      handler() {
        this.virify()
      }
    }
  }
}